package com.ruoyi.web.controller.match;

import java.util.List;

import com.ruoyi.match.domain.MatchAttachments;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.match.domain.MatchWoek;
import com.ruoyi.match.service.IMatchWoekService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 作品Controller
 * 
 * @author 星野漫游
 * @date 2024-06-02
 */
@Controller
@RequestMapping("/match/woek")
@Api("作品管理")
public class MatchWoekController extends BaseController
{
    private String prefix = "match/woek";

    @Autowired
    private IMatchWoekService matchWoekService;

    @RequiresPermissions("match:woek:view")
    @GetMapping()
    public String woek()
    {
        return prefix + "/woek";
    }

    /**
     * 查询作品列表
     */
    @RequiresPermissions("match:woek:list")
    @PostMapping("/list")
    @ResponseBody
    @ApiOperation("作品列表查询")
    public TableDataInfo list(@RequestBody MatchWoek matchWoek)
    {
        startPage();
        List<MatchWoek> list = matchWoekService.selectMatchWoekList(matchWoek);
        return getDataTable(list);
    }

    /**
     * 查询作品详情
     */
    @RequiresPermissions("match:woek:details")
    @GetMapping ("/details")
    @ResponseBody
    @ApiOperation("作品列表查询")
    public TableDataInfo details(MatchWoek matchWoek)
    {

        List<MatchAttachments> list=matchWoekService.chechDetails(matchWoek);
        return getDataTable(list);
    }

    /**
     * 导出作品列表
     */
    @RequiresPermissions("match:woek:export")
    @Log(title = "作品", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    @ApiOperation("导出作品列表")
    public AjaxResult export(MatchWoek matchWoek)
    {
        List<MatchWoek> list = matchWoekService.selectMatchWoekList(matchWoek);
        ExcelUtil<MatchWoek> util = new ExcelUtil<MatchWoek>(MatchWoek.class);
        return util.exportExcel(list, "作品数据");
    }

    /**
     * 新增作品
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存作品
     */
    @RequiresPermissions("match:woek:add")
    @Log(title = "作品", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(MatchWoek matchWoek)
    {
        return toAjax(matchWoekService.insertMatchWoek(matchWoek));
    }

    /**
     * 修改作品
     */
    @RequiresPermissions("match:woek:edit")
    @GetMapping("/edit/{workId}")
    public String edit(@PathVariable("workId") Long workId, ModelMap mmap)
    {
        MatchWoek matchWoek = matchWoekService.selectMatchWoekByWorkId(workId);
        mmap.put("matchWoek", matchWoek);
        return prefix + "/edit";
    }

    /**
     * 修改保存作品
     */
    @RequiresPermissions("match:woek:edit")
    @Log(title = "作品", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(MatchWoek matchWoek)
    {
        return toAjax(matchWoekService.updateMatchWoek(matchWoek));
    }

    /**
     * 删除作品
     */
    @RequiresPermissions("match:woek:remove")
    @Log(title = "作品", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(matchWoekService.deleteMatchWoekByWorkIds(ids));
    }
}
